﻿using CodeMan.Rabbitmq.Common;
using System.Text;
using System;
using RabbitMQ.Client;

namespace CodeMan.Rabbitmq.Producer.Producer
{
    public class WeatherFanout
    {
        public static void Weather()
        {
            using (var connection = RabbitUtils.GetConnection().CreateConnection())
            {
                using (var channel = connection.CreateModel())
                {
                    int count = 5;
                    for (var i = 0; i < count; i++)
                    {
                        string message = $"{i + 20}度";
                        var body = Encoding.UTF8.GetBytes(message);
                        //发布消息
                        channel.BasicPublish(RabbitConstant.EXCHANGE_WEATHER, "", null, body);
                        Console.WriteLine($"正在发送天气信息：{message}");
                        //Console.WriteLine("WeatherFanout【{0}】发送天气信息成功！", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    }
                    Console.WriteLine("【{0}】已经成功发送{1}条数据", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), count);
                }
            }
        }
    }
}